﻿{include file="common/header" /}
<link rel="stylesheet" href="__STATIC__/static/css/warehouse.css?v={{:config('STATIC_VERSION')}}">
<article class="page-container">
	<form action="" method="post" class="form form-horizontal" id="myform">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>搜索用户：</label>
			<div class="formControls col-xs-8 col-sm-9 search-box">
				<input type="text" class="input-text" value="" placeholder="用户名" id="UserName" autocomplete="off" >
				<ul class="user-lists" id="user-lists">

				</ul>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>仓库：</label>
			<div class="formControls col-xs-8 col-sm-9">
			<span class="select-box">
				<select class="select valid" size="1" name="WareHouse" id="WareHouse">
					{foreach $wareHouses as $wareHouse}
					<option value="{{$wareHouse->LocationCode}}" data-name="{{$wareHouse->Name}} Warehouse">{{$wareHouse->Name}}</option>
					{/foreach}
					</select>
				</span>
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<button type="button" class="btn btn-success radius" id="save-btn" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
			</div>
		</div>
		<input type="hidden" name="UserID" id="UserID">
		<input type="hidden" name="Name" id="Name" value="">
	</form>
</article>
<script>


	//初始化仓库选项
    var init_name = $('#WareHouse').find('option:first').data('name');
    $('#Name').val(init_name)
</script>
<script>

	//异步获取用户列表
	$('#UserName').keydown(function () {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "{{:url('/api/staff/lists')}}" ,
            data: {UserName:$('#UserName').val()},
            success: function (result) {
                if(result.code==200){
                    var html='';
                    $.each(result.msg,function (k,v) {
                        html+='<li data-UserID="'+v.ID+'"> '+v.NameENLong+'   '+v.DepartmentName+'</li>';
                    });
                    $('#user-lists').html(html).show();
				}else{
                    $('#user-lists').hide();
				}
            },
            error : function() {
                layer.msg('异常!',{icon:1,time:100000000});

            }
        });
    });


	//监听用户输入
	$('#UserName').blur(function () {
	    setTimeout('$("#user-lists").hide();',300);  //防止隐藏的太快
    });
	$('#user-lists').on('click','li',function () {
		 var userId = $(this).data('userid');
		 $('#UserName').val($(this).text())
		 $('#UserID').val(userId)
    });

	$('#WareHouse').click(function () {
		var Name = $(this).find('option:selected').data('name');
		$('#Name').val(Name)
    });

	$('#save-btn').click(function () {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "{{:url('/warehouse/create_manage')}}" ,
            data: $('#myform').serialize(),
            success: function (result) {
                if (result.code == 200) {
                    layer.msg('添加成功!',{icon:1,time:1000},function (index) {
                        parent.location.reload();
                    });
                }else{
                    layer.msg(result.msg,{icon:1,time:1000});
				}
            },
            error : function() {
                layer.msg('异常!',{icon:1,time:100000000});

            }
        });
    })
</script>
{include file="common/header" /}